home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / SETUP / US / CBUILDER / DATA.Z / WINSOCK.H < prev    next >
C/C++ Source or Header  |  1997-02-13  |  34KB  |  966 lines

  1. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  2.  * Copyright (c) 1993-1996, Microsoft Corp. All rights reserved.
  3.  *
  4.  * This header file corresponds to version 1.1 of the Windows Sockets specification.
  5.  *
  6.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  7.  * of the University of California.  All rights reserved.  The
  8.  * Berkeley Software License Agreement specifies the terms and
  9.  * conditions for redistribution.
  10.  *
  11.  */
  12.  
  13. #ifndef _WINSOCKAPI_
  14. #define _WINSOCKAPI_
  15. #pragma option -b
  16.  
  17. /*
  18.  * Pull in WINDOWS.H if necessary
  19.  */
  20. #ifndef _INC_WINDOWS
  21. #pragma option -b.
  22. #include <windows.h>
  23. #pragma option -b
  24. #endif /* _INC_WINDOWS */
  25.  
  26. /*
  27.  * Basic system type definitions, taken from the BSD file sys/types.h.
  28.  */
  29. typedef unsigned char   u_char;
  30. typedef unsigned short  u_short;
  31. typedef unsigned int    u_int;
  32. typedef unsigned long   u_long;
  33.  
  34. /*
  35.  * The new type to be used in all
  36.  * instances which refer to sockets.
  37.  */
  38. typedef u_int           SOCKET;
  39.  
  40. /*
  41.  * Select uses arrays of SOCKETs.  These macros manipulate such
  42.  * arrays.  FD_SETSIZE may be defined by the user before including
  43.  * this file, but the default here should be >= 64.
  44.  *
  45.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  46.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  47.  */
  48. #ifndef FD_SETSIZE
  49. #define FD_SETSIZE      64
  50. #endif /* FD_SETSIZE */
  51.  
  52. typedef struct fd_set {
  53.         u_int   fd_count;               /* how many are SET? */
  54.         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  55. } fd_set;
  56.  
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60.  
  61. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  62.  
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66.  
  67.  
  68. #define FD_CLR(fd, set) do { \
  69.     u_int __i; \
  70.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  71.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  72.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  73.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  74.                     ((fd_set FAR *)(set))->fd_array[__i+1]; \
  75.                 __i++; \
  76.             } \
  77.             ((fd_set FAR *)(set))->fd_count--; \
  78.             break; \
  79.         } \
  80.     } \
  81. } while(0)
  82.  
  83. #define FD_SET(fd, set) do { \
  84.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  85.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
  86. } while(0)
  87.  
  88. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  89.  
  90. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))
  91.  
  92. /*
  93.  * Structure used in select() call, taken from the BSD file sys/time.h.
  94.  */
  95. struct timeval {
  96.         long    tv_sec;         /* seconds */
  97.         long    tv_usec;        /* and microseconds */
  98. };
  99.  
  100. /*
  101.  * Operations on timevals.
  102.  *
  103.  * NB: timercmp does not work for >= or <=.
  104.  */
  105. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  106. #define timercmp(tvp, uvp, cmp) \
  107.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  108.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  109. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  110.  
  111. /*
  112.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  113.  *
  114.  *
  115.  * Ioctl's have the command encoded in the lower word,
  116.  * and the size of any in or out parameters in the upper
  117.  * word.  The high 2 bits of the upper word are used
  118.  * to encode the in/out status of the parameter; for now
  119.  * we restrict parameters to at most 128 bytes.
  120.  */
  121. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  122. #define IOC_VOID        0x20000000      /* no parameters */
  123. #define IOC_OUT         0x40000000      /* copy out parameters */
  124. #define IOC_IN          0x80000000      /* copy in parameters */
  125. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  126.                                         /* 0x20000000 distinguishes new &
  127.                                            old ioctl's */
  128. #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
  129.  
  130. #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  131.  
  132. #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  133.  
  134. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  135. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  136. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  137.  
  138. /* Socket I/O Controls */
  139. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  140. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  141. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  142. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  143. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  144.  
  145. /*
  146.  * Structures returned by network data base library, taken from the
  147.  * BSD file netdb.h.  All addresses are supplied in host order, and
  148.  * returned in network order (suitable for use in system calls).
  149.  */
  150.  
  151. struct  hostent {
  152.         char    FAR * h_name;           /* official name of host */
  153.         char    FAR * FAR * h_aliases;  /* alias list */
  154.         short   h_addrtype;             /* host address type */
  155.         short   h_length;               /* length of address */
  156.         char    FAR * FAR * h_addr_list; /* list of addresses */
  157. #define h_addr  h_addr_list[0]          /* address, for backward compat */
  158. };
  159.  
  160. /*
  161.  * It is assumed here that a network number
  162.  * fits in 32 bits.
  163.  */
  164. struct  netent {
  165.         char    FAR * n_name;           /* official name of net */
  166.         char    FAR * FAR * n_aliases;  /* alias list */
  167.         short   n_addrtype;             /* net address type */
  168.         u_long  n_net;                  /* network # */
  169. };
  170.  
  171. struct  servent {
  172.         char    FAR * s_name;           /* official service name */
  173.         char    FAR * FAR * s_aliases;  /* alias list */
  174.         short   s_port;                 /* port # */
  175.         char    FAR * s_proto;          /* protocol to use */
  176. };
  177.  
  178. struct  protoent {
  179.         char    FAR * p_name;           /* official protocol name */
  180.         char    FAR * FAR * p_aliases;  /* alias list */
  181.         short   p_proto;                /* protocol # */
  182. };
  183.  
  184. /*
  185.  * Constants and structures defined by the internet system,
  186.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  187.  */
  188.  
  189. /*
  190.  * Protocols
  191.  */
  192. #define IPPROTO_IP              0               /* dummy for IP */
  193. #define IPPROTO_ICMP            1               /* control message protocol */
  194. #define IPPROTO_IGMP            2               /* group management protocol */
  195. #define IPPROTO_GGP             3               /* gateway^2 (deprecated) */
  196. #define IPPROTO_TCP             6               /* tcp */
  197. #define IPPROTO_PUP             12              /* pup */
  198. #define IPPROTO_UDP             17              /* user datagram protocol */
  199. #define IPPROTO_IDP             22              /* xns idp */
  200. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  201.  
  202. #define IPPROTO_RAW             255             /* raw IP packet */
  203. #define IPPROTO_MAX             256
  204.  
  205. /*
  206.  * Port/socket numbers: network standard functions
  207.  */
  208. #define IPPORT_ECHO             7
  209. #define IPPORT_DISCARD          9
  210. #define IPPORT_SYSTAT           11
  211. #define IPPORT_DAYTIME          13
  212. #define IPPORT_NETSTAT          15
  213. #define IPPORT_FTP              21
  214. #define IPPORT_TELNET           23
  215. #define IPPORT_SMTP             25
  216. #define IPPORT_TIMESERVER       37
  217. #define IPPORT_NAMESERVER       42
  218. #define IPPORT_WHOIS            43
  219. #define IPPORT_MTP              57
  220.  
  221. /*
  222.  * Port/socket numbers: host specific functions
  223.  */
  224. #define IPPORT_TFTP             69
  225. #define IPPORT_RJE              77
  226. #define IPPORT_FINGER           79
  227. #define IPPORT_TTYLINK          87
  228. #define IPPORT_SUPDUP           95
  229.  
  230. /*
  231.  * UNIX TCP sockets
  232.  */
  233. #define IPPORT_EXECSERVER       512
  234. #define IPPORT_LOGINSERVER      513
  235. #define IPPORT_CMDSERVER        514
  236. #define IPPORT_EFSSERVER        520
  237.  
  238. /*
  239.  * UNIX UDP sockets
  240.  */
  241. #define IPPORT_BIFFUDP          512
  242. #define IPPORT_WHOSERVER        513
  243. #define IPPORT_ROUTESER